package com.ls.fw.data.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ls.fw.data.config.DataConfig;
import com.ls.fw.data.config.DataConfigImpl;


/**
 * ControlDataDao适配器
 * 
 * @author lisheng
 * @date 2014年12月29日 下午7:35:27
 * @version V1.0
 */
public abstract class ControlDataDaoAdapter implements ControlDataDao{
	
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	// 服务是否关闭
	protected boolean closed = true;
	
	protected DataConfig dataConfig = DataConfigImpl.getInstance();
	
	protected boolean autoCommit = dataConfig.isAutoCommit();
	
	//服务地址
	protected Object address = dataConfig.getAddress();
	
	protected String prikeyName = dataConfig.getPriKeyName();
	
	public ControlDataDaoAdapter() {
		super();
	}

	@Override
	public boolean isClosed() {
		return closed;
	}

 
	@Override
	public boolean isAutoCommit() {
		return autoCommit;
	}

	@Override
	public Object getAddress() {
		return address;
	}

	@Override
	public boolean reopen() {
		this.close();
		return this.open(address);
	}
	
	@Override
	public boolean open() {
		return this.open(address);
	}

	@Override
	public boolean commit() {
		return this.commit(false);
	}

	@Override
	public boolean commit(boolean softCommit) {
		//忽略
		return true;
	}

	@Override
	public boolean rollback() {
		//忽略
		return true;
	}

	@Override
	public void optimize() {
		//忽略
	}

	@Override
	public void close() {
		//忽略
	}

	@Override
	public DataConfig getDataConfig() {
		return dataConfig;
	}


	public void setClosed(boolean closed) {
		this.closed = closed;
	}

	public void setDataConfig(DataConfig dataConfig) {
		this.dataConfig = dataConfig;
	}

	public void setAutoCommit(boolean autoCommit) {
		this.autoCommit = autoCommit;
	}

	public void setAddress(Object address) {
		this.address = address;
	}

	@Override
	public <S> S switchServer(Object address) {
		return this.getServer();
	}

	@Override
	public boolean open(Object address) {
		this.switchServer(address);
		return true;
	}
	
	public String getPrikeyName(){
		return prikeyName;
	}
	
	
//	public String getConfigPath(){
//		return this.dataConfig.g
//	}
}
